package cn.xabad.server.thea.controller

import org.apache.poi.ss.usermodel.CellType
import org.apache.poi.xssf.usermodel.XSSFWorkbook
import org.joda.time.DateTime
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import org.springframework.stereotype.Controller
import org.springframework.ui.Model
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.ResponseBody
import java.io.FileInputStream
import java.text.DecimalFormat

@Controller
class IndexController {
    val log: Logger = LoggerFactory.getLogger(IndexController::class.java)

    @GetMapping("/v")
    fun index(mv: Model): String {
        return "v"
    }
    @GetMapping("/")
    fun dft(mv: Model): String {
        return "v"
    }

    @GetMapping("/log")
    fun log(): String {
        return "log"
    }

    @GetMapping("/a")
    @ResponseBody
    fun import(): String {
        val df = DecimalFormat("0")
        val workbook = XSSFWorkbook(FileInputStream("/Users/xueyong/Downloads/点击练习未排队异常分析0530.xlsx"))
        workbook.sheetIterator().forEach l@{ sheet ->
            IntRange(0, sheet.physicalNumberOfRows-1).forEach le@ {
                val row =  sheet.getRow(it)
                val cols =row.physicalNumberOfCells
                val idCell = row.getCell(1)
                val timeCell = row.getCell(2)
                if (idCell.cellTypeEnum == CellType.NUMERIC) {
                println(df.format(idCell.numericCellValue))
                }
                if (timeCell.cellTypeEnum == CellType.NUMERIC) {
                    println(DateTime(timeCell.dateCellValue).toString("HH:mm:ss"))
                }
                return@l
            }
        }
        return "v"
    }
}